package com.chuxi.demo;

import org.junit.Test;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;

/**
 * @ Author:任留辉
 * @ Description:
 * @ Date:Created in 19:52 2021/7/23 0023
 */
public class ProxyTest {
    @Test
    public void test() {
        personImpl person = new personImpl();
        person p2 = (person) Proxy.newProxyInstance(person.getClass().getClassLoader(), person.getClass().getInterfaces(), (proxy, method, args) -> {
            System.out.println("前");
            Integer res = (Integer) method.invoke(person, args);
            res+=20;
            System.out.println("后");
            return res;
        });
        System.out.println(p2.add(20, 30));
    }
}
